package com.wyh.user.config;

import com.wyh.user.constant.Constant;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {
    @Bean
    public Queue userQueue(){
        return QueueBuilder.durable(Constant.USER_QUEUE).build();
    }

    @Bean
    public DirectExchange userExchange(){
        return ExchangeBuilder.directExchange(Constant.USER_EXCHANGE).build();
    }

    @Bean
    public Binding userBinding(@Qualifier("userQueue") Queue queue,
                               @Qualifier("userExchange") DirectExchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with(Constant.USER_BINDING_KEY);
    }
}
